<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改资讯')" />
    <th:block th:include="include :: summernote-css" />
    <style>
        .grid{
            width:200px;
            min-height:100px;
            padding: 15px;
            background:#fff;
            margin:8px;
            font-size:12px;
            float:left;
            box-shadow: 0 1px 3px rgba(34,25,25,0.4);
            -moz-box-shadow: 0 1px 3px rgba(34,25,25,0.4);
            -webkit-box-shadow: 0 1px 3px rgba(34,25,25,0.4);

            -webkit-transition: top 1s ease, left 1s ease;
            -moz-transition: top 1s ease, left 1s ease;
            -o-transition: top 1s ease, left 1s ease;
            -ms-transition: top 1s ease, left 1s ease;
        }


        .videoBox{
            width:600px;
            padding: 15px;
            background:#fff;
            margin:8px;
            font-size:12px;
            float:left;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-news-edit" th:object="${news}">
            <input name="newId" th:field="*{newId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">资讯标题：</label>
                <div class="col-sm-8">
                    <input name="newTitle" th:field="*{newTitle}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">资讯分类：</label>
                <div class="col-sm-8">
                    <input name="typeName" th:field="*{typeName}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">归属部门：</label>
                <div class="col-sm-8">
                    <input name="deptName" th:field="*{deptName}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资讯内容：</label>
                <div class="col-sm-8">
                    <input id="newContent" name="newContent" th:field="*{newContent}" class="form-control"  type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>
            <!--<div class="form-group">-->
                <!--<label class="col-sm-3 control-label">上传文件：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<input name="newFile" th:field="*{newFile}" class="form-control" type="hidden">-->
                    <!--<div class="row">-->
                        <!--<input id="files" name="files" th:value="${files}" class="form-control"  type="hidden">-->
                        <!--<div  class="col-sm-12" th:if="${files!=null && #lists.size(files)>0}">-->
                            <!--<th:block th:each="name:${files}">-->
                                <!--<div class="file-box">-->
                                    <!--<div class="grid">-->
                                        <!--<div  class="imgholder">-->
                                            <!--<img name="newFile" data-magnify="gallery" th:data-src="${name}" th:src="${name}"   style='width:150px;height:150px;' ></img>-->
                                        <!--</div>-->

                                    <!--</div>-->
                                <!--</div>-->
                            <!--</th:block>-->
                        <!--</div>-->
                        <!--<div class="col-sm-12" th:if="${files==null || #lists.size(files)<1}">-->
                            <!--<span>暂无文件！</span>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传视频：</label>
                <div class="col-sm-8">

                    <div class="row">
                        <input name="newVideo" th:field="*{newVideo}" class="form-control" type="hidden">
                        <div id="photosDiv" class="col-sm-12" th:if="${videos!=null && #lists.size(videos)>0}">
                            <th:block th:each="name:${videos}">
                                <div class="">
                                    <div  class="videoBox" >
                                        <div  class="" >
                                            <video name="newVideo" th:src="${name}"  autoplay style='width:600px;height:500px;' ></video>
                                        </div>

                                    </div>
                                </div>
                            </th:block>
                        </div>
                        <div class="col-sm-12" th:if="${videos==null || #lists.size(videos)<1}">
                            <span>暂无视频！</span>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "module/news";
        $("#form-news-edit").validate({
            focusCleanup: true
        });

        $(function() {
            $('.summernote').summernote({
                placeholder: '请输入内容',
                height : 400,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                }
            });
            var content = $("#newContent").val();
            $('#editor').summernote('code', content);
        });

        // 上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
                $("#newContent").val(sHTML);
               //$.operate.save(prefix + "/edit", $('#form-news-edit').serialize());
                $.modal.close();
            }
        }
    </script>
</body>
</html>